package com.dex4d.ui.qr.model;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.dex4d.R;
import com.dex4d.ui.main.model.Dex4dTrade;
import com.google.gson.annotations.Expose;

/**
 * 作者    LiQingyi
 * 时间    2018/11/20 18:09
 * 文件    dex4d-android
 * 描述
 */
public class PayData implements Parcelable {
    public String desc;//操作类型
    public String symbol;//代币类型
    public String swapA;//对倒时tokenA
    public String swapB;//对倒时tokenB
    public String amountA;//花费数量 对倒值1
    public String amountB;//预估数量 对倒值2
    public String gasLimit;//
    public String account;//交易账户
    public String from;//发起交易地址
    public String to;//收交易地址
    public String referrer;//推荐人

    @Expose
    public String txHash; //交易Hash请求之后方可获得

    @Expose
    public String txFee; //交易Hash请求之后方可获得


    public PayData() {
    }

    /**
     * 展示货币符号使用此方法
     *
     * @return
     */
    public String getSymbol() {
        if (TextUtils.isEmpty(symbol)) {
            symbol = Dex4dTrade.ETH;
        }
        return symbol.toUpperCase();
    }

    public String getDesc(Context context) {
        int resId = context.getResources().getIdentifier("qr_pay_auth_flag_" + desc, "string", context.getPackageName());
        return context.getResources().getString(resId);
    }

    public String getAmount(Context context) {

        if (TextUtils.equals(desc, "buy")||TextUtils.equals(desc, "reinvest")) {//买入 ok
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount_m), amountB, amountA, getSymbol());
        }

        else if (TextUtils.equals(desc, "buyreferral")) {//???
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount), amountA, Dex4dTrade.ETH);
        }

        else if (TextUtils.equals(desc, "sell")) {//卖出 ok
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount_m), amountA, amountB, getSymbol());
        }

        else if (TextUtils.equals(desc, "swap")) {//对倒 ok
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount_m), amountA, amountB, getSymbol());
        }

        else if (TextUtils.equals(desc, "withdraw")) {//提现 ok
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount), amountA, getSymbol());
        }

        else if (TextUtils.equals(desc, "buyswap")) {//???
            return String.format(context.getResources().getString(R.string.qr_pay_auth_amount), amountA, Dex4dTrade.ETH);
        }

        return String.format(context.getResources().getString(R.string.qr_pay_auth_amount), amountA, getSymbol());

    }

    @Override
    public String toString() {
        return "PayData{" +
                "desc='" + desc + '\'' +
                ", symbol='" + symbol + '\'' +
                ", swapA='" + swapA + '\'' +
                ", swapB='" + swapB + '\'' +
                ", amountA='" + amountA + '\'' +
                ", amountB='" + amountB + '\'' +
                ", gasLimit='" + gasLimit + '\'' +
                ", account='" + account + '\'' +
                ", from='" + from + '\'' +
                ", to='" + to + '\'' +
                ", txHash='" + txHash + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.desc);
        dest.writeString(this.symbol);
        dest.writeString(this.swapA);
        dest.writeString(this.swapB);
        dest.writeString(this.amountA);
        dest.writeString(this.amountB);
        dest.writeString(this.gasLimit);
        dest.writeString(this.account);
        dest.writeString(this.from);
        dest.writeString(this.to);
        dest.writeString(this.referrer);
        dest.writeString(this.txHash);
        dest.writeString(this.txFee);
    }

    protected PayData(Parcel in) {
        this.desc = in.readString();
        this.symbol = in.readString();
        this.swapA = in.readString();
        this.swapB = in.readString();
        this.amountA = in.readString();
        this.amountB = in.readString();
        this.gasLimit = in.readString();
        this.account = in.readString();
        this.from = in.readString();
        this.to = in.readString();
        this.referrer = in.readString();
        this.txHash = in.readString();
        this.txFee = in.readString();
    }

    public static final Creator<PayData> CREATOR = new Creator<PayData>() {
        @Override
        public PayData createFromParcel(Parcel source) {
            return new PayData(source);
        }

        @Override
        public PayData[] newArray(int size) {
            return new PayData[size];
        }
    };
}
